package com.ctrip.ec.api.admin.aop;

import com.ctrip.ec.api.admin.common.RequestContext;
import com.ctrip.ec.dal.EntityBase;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.bouncycastle.cert.ocsp.Req;
import org.springframework.stereotype.Component;

import java.sql.Timestamp;

/**
 * Created by jiang on 2018/9/2.
 */
@Component
@Aspect
public class SaveAspect {

    @Pointcut("execution(* com.ctrip.ec.api.admin.controller..*.save(com.ctrip.ec.dal.EntityBase+,..))")
    public void before(){}

    @Before("before() && args(entity,..)")
    public void beforeAdvide(JoinPoint point, EntityBase entity){
        if(entity.add()){
            entity.fieldValue("is_delete",false);
            entity.fieldValue("create_time",new Timestamp(System.currentTimeMillis()));
            entity.fieldValue("user_id", RequestContext.getUserId());
            entity.fieldValue("user_name",RequestContext.getUserName());
        }
        entity.fieldValue("update_time",new Timestamp(System.currentTimeMillis()));

    }

}
